

#ifndef UD_XGRAPH_H
#define UD_XGRAPH_H 1

#include "zgraph.h"
#include "zAdAChar.h"

#pragma pack (push, 8)

class UcDbXrefGraphNode : public UcDbGraphNode
{
public:
    UcDbXrefGraphNode(const ZTCHAR * pName = NULL,
        const UcDbObjectId& btrId = UcDbObjectId::kNull,
        UcDbDatabase* pDb = NULL,
        UcDb::XrefStatus status = UcDb::kXrfResolved);
    virtual ~UcDbXrefGraphNode();

    const ZTCHAR * name() const;
    UcDbObjectId btrId() const;
    UcDbDatabase* database() const;

    Ucad::ErrorStatus setName(const ZTCHAR * pName);
    void setBtrId(const UcDbObjectId& id);
    void setDatabase(UcDbDatabase* pDb);

    bool isNested() const;

    UcDb::XrefStatus xrefStatus() const;
    void setXrefStatus(UcDb::XrefStatus stat);

    UcDb::XrefNotificationStatus xrefNotificationStatus() const;
    void setXrefNotificationStatus(UcDb::XrefNotificationStatus stat);

    void*   xData() { return mpxdata; }
    void    setxData(void *pXData) { mpxdata = pXData; }

    Ucad::ErrorStatus xrefReadSubstatus() const;

private:
    void* mpxdata; 
    ZTCHAR * mpName;
    UcDbObjectId mBtrId;
    
    UcDb::XrefStatus mStatus;
    UcDb::XrefNotificationStatus mNotifyStatus;
};

class UcDbXrefGraph : public UcDbGraph
{
public:
    UcDbXrefGraph(UcDbXrefGraphNode* pHostDwg = NULL);
    virtual ~UcDbXrefGraph();

    UcDbXrefGraphNode* xrefNode(const ZTCHAR * pName) const;
    UcDbXrefGraphNode* xrefNode(UcDbObjectId btrId) const;
    UcDbXrefGraphNode* xrefNode(const UcDbDatabase* pDb) const;

    UcDbXrefGraphNode* xrefNode(int idx) const;
    UcDbXrefGraphNode*  hostDwg() const;

    ZSoft::Boolean markUnresolvedTrees ();

    virtual ZSoft::Boolean findCycles(UcDbGraphNode* pStart = NULL);
};

Ucad::ErrorStatus ucedGetCurDwgXrefGraph(UcDbXrefGraph&,
    ZSoft::Boolean includeGhosts = ZSoft::kFalse);

inline const ZTCHAR * UcDbXrefGraphNode::name() const { return mpName; }
inline UcDbObjectId UcDbXrefGraphNode::btrId() const { return mBtrId; }
inline UcDbDatabase* UcDbXrefGraphNode::database() const
     { return (UcDbDatabase*)data(); }

inline void UcDbXrefGraphNode::setBtrId(const UcDbObjectId& id)
    { mBtrId = id; }
inline void UcDbXrefGraphNode::setDatabase(UcDbDatabase* pDb)
    { setData(pDb); }

inline bool UcDbXrefGraphNode::isNested() const
    { return !isMarkedAs(kFirstLevel); }

inline UcDb::XrefStatus UcDbXrefGraphNode::xrefStatus() const
    { return mStatus; }
inline void UcDbXrefGraphNode::setXrefStatus(UcDb::XrefStatus stat)
    { mStatus = stat; }
inline UcDb::XrefNotificationStatus
UcDbXrefGraphNode::xrefNotificationStatus() const
    { return mNotifyStatus; }
inline void UcDbXrefGraphNode::setXrefNotificationStatus(
    UcDb::XrefNotificationStatus stat)
    { mNotifyStatus = stat; }

inline UcDbXrefGraphNode* UcDbXrefGraph::xrefNode(int idx) const
    { return (UcDbXrefGraphNode*)node(idx); }

inline UcDbXrefGraphNode* UcDbXrefGraph::hostDwg() const
    { return (UcDbXrefGraphNode*)rootNode(); }

#pragma pack (pop)

#endif

